varying vec3 normalV, lightV, eyeV,lightV2;
varying vec4 ambient;

uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;


void main(void)
{
	vec4 blanc 	= vec4(0.2);
	vec4 color 	= vec4(0.5);
  	float fdelta 	= 0.2; 
	float fseuil = 0.01;
	float fecart = 0.1;
	
	
	//attenuation
	float d = length(lightV2);
	float att = 1/(gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation*d + gl_LightSource[0].quadraticAttenuation*d*d);
	
	vec4 finalColor = ambient;

	vec3 N = normalize(normalV);
	vec3 E = normalize(eyeV);
	vec3 L = normalize(lightV);

	vec3 R = reflect(-L, N);
	float coeffD = max(dot(N,L),0.0);

	if(coeffD > 0.0){
		vec4 diffuse = coeffD * gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse ;	
		vec4 specular = pow(max(dot(R,E),0.0),gl_FrontMaterial.shininess) * gl_FrontMaterial.specular * gl_LightSource[0].specular ;
		finalColor += (diffuse + specular) * att;
	}
	gl_FragColor = finalColor * texture2D(tex1, gl_TexCoord[0]);
	
	
	//Procedural carreaux
	/*vec4 TexCoord = gl_TexCoord[0]*10.0;
	if (mod(TexCoord.x, fecart) < fseuil ||  mod(TexCoord.y, fecart) < fseuil)
	{
		gl_FragColor = color;
	}
	else
	{
		gl_FragColor = blanc;
	}
	gl_FragColor.a = 1.0;*/
	
}